//
//  MethodMacro.h
//  
//
//  Created by limaohuyu on 2020/7/3.
//  Copyright © 2020 czw. All rights reserved.
//

#ifndef MethodMacro_h
#define MethodMacro_h

#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )

#define kSafeString(str) kStringIsEmpty(str) ? @"" : str



 #ifndef    weakify
 #if __has_feature(objc_arc)

 #define weakify( x ) \
 _Pragma("clang diagnostic push") \
 _Pragma("clang diagnostic ignored \"-Wshadow\"") \
 autoreleasepool{} __weak __typeof__(x) __weak_##x##__ = x; \
 _Pragma("clang diagnostic pop")

 #else

 #define weakify( x ) \
 _Pragma("clang diagnostic push") \
 _Pragma("clang diagnostic ignored \"-Wshadow\"") \
 autoreleasepool{} __block __typeof__(x) __block_##x##__ = x; \
 _Pragma("clang diagnostic pop")

 #endif
 #endif

 #ifndef    strongify
 #if __has_feature(objc_arc)

 #define strongify( x ) \
 _Pragma("clang diagnostic push") \
 _Pragma("clang diagnostic ignored \"-Wshadow\"") \
 try{} @finally{} __typeof__(x) x = __weak_##x##__; \
 _Pragma("clang diagnostic pop")

 #else

 #define strongify( x ) \
 _Pragma("clang diagnostic push") \
 _Pragma("clang diagnostic ignored \"-Wshadow\"") \
 try{} @finally{} __typeof__(x) x = __block_##x##__; \
 _Pragma("clang diagnostic pop")

 #endif
 #endif


#undef    singleton
#define singleton( __class ) \
property (nonatomic, readonly) __class * sharedInstance; \
- (__class *)sharedInstance; \
+ (__class *)sharedInstance;

#undef    def_singleton
#define def_singleton( __class ) \
dynamic sharedInstance; \
- (__class *)sharedInstance \
{ \
return [__class sharedInstance]; \
} \
+ (__class *)sharedInstance \
{ \
static dispatch_once_t once; \
static __strong id __singleton__ = nil; \
dispatch_once( &once, ^{ __singleton__ = [[__class alloc] init]; } ); \
return __singleton__; \
}

#ifdef DEBUG

#define WGLog(...)  printf("\n\t<%s line%d>\n%s\n", __FUNCTION__,__LINE__,[[NSString stringWithFormat:__VA_ARGS__] UTF8String])
#else
#define WGLog(...)
#define NSLog(...) {}
#endif


#endif /* MethodMacro_h */
